//
//  SCPredefine.h
//  Scalper
//
//  Created by 王云 on 2017/9/14.
//  Copyright © 2017年 WY. All rights reserved.
//

#ifndef SCPredefine_h
#define SCPredefine_h


//颜色
#define KGreenColor   [UIColor colorWithRed:74/255.0 green:177/255.0 blue:100/255.0 alpha:1]

#define KOrange     [UIColor colorWithRed:255/255.0 green:108/255.0 blue:55/255.0 alpha:1]

#define DarkColor       [UIColor colorWithRed:239/255.0 green:239/255.0 blue:243/255.0 alpha:1]
#define TitleDarkColor       [UIColor colorWithRed:180/255.0 green:172/255.0 blue:160/255.0 alpha:1]

//navigationbar 颜色
#define KnavigationbarColor  [UIColor colorWithRed:141/255.0 green:37/255.0 blue:251/255.0 alpha:1]

//轮播图高度 细节： 整数除  获得的是整数
#define kADH        kWidth/1241*581 


// 1.判断是否为iOS7以上
#define iOS7 ([[UIDevice currentDevice].systemVersion doubleValue] >= 7.0)
#define iOS8  __IPHONE_OS_VERSION_MIN_REQUIRED >= 80000
#define iOS9 ([[UIDevice currentDevice].systemVersion doubleValue] >= 9.0)
// 2.获得RGB颜色
#define WYColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]
#define WYColorA(r, g, b,c) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:c]

//根据16进制数设置颜色
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]

// 3.自定义Log

#ifdef DEBUG
#define DLog(format, ...) printf("[%s] %s [第%d行] %s\n", __TIME__, __FUNCTION__, __LINE__, [[NSString stringWithFormat:format, ## __VA_ARGS__] UTF8String]);
#else
#define DLog(format, ...)
#endif

//#ifdef DEBUG
//#define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
////#define DLog(fmt, ...) NSLog((@"[文件:%s]\n" "[函数:%s]\n" "[行:%d] \n" fmt), __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__);
//#else
//#define DLog(...)
//#endif
// 4.是否为4inch
#define fourInch ([UIScreen mainScreen].bounds.size.height == 568)
//
#define isIphone4 ([UIScreen mainScreen].bounds.size.height == 480)
#define isIphone5 ([UIScreen mainScreen].bounds.size.height == 568)
#define isIphone6 ([UIScreen mainScreen].bounds.size.height == 667)
#define isIphone6p ([UIScreen mainScreen].bounds.size.height == 736)
#define isIphoneX ([UIScreen mainScreen].bounds.size.height == 812)

//5.常用字体
#define HW_TEXTSIZE(text, font) [text length] > 0 ? [text \
sizeWithAttributes:@{NSFontAttributeName:font}] : CGSizeZero;

#define HW_MULTILINE_TEXTSIZE(text, font, maxSize, mode) [text length] > 0 ? [text \
boundingRectWithSize:maxSize options:(NSStringDrawingUsesLineFragmentOrigin) \
attributes:@{NSFontAttributeName:font} context:nil].size : CGSizeZero;

//6.常用目录
#define kDirDoc ([NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject])
#define kDirCache ([NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)lastObject])

//常用
#define kWidth  [UIScreen mainScreen].bounds.size.width
#define KHeight  [UIScreen mainScreen].bounds.size.height
#define KHeightS   ([UIScreen mainScreen].bounds.size.height-64)
#define KHeightL  ([UIScreen mainScreen].bounds.size.height-64-49)
#define KMainScreen  [UIScreen mainScreen].bounds
#define KAppliactionFrame  [[UIApplication sharedApplication] statusBarFrame]

#define KQueueGlobal dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
#define KQueueMain dispatch_get_main_queue()


//单
// ----------------------------------
// Code block
// ----------------------------------
// 单例模式
#define HWSINGLETON
static id sharedInstance;
#define hw_as_singleton    \
+ (instancetype)sharedInstance; \
+ (void)purgeSharedInstance;

#define hw_def_singleton( __token) \
static id __singleton__objc__##__token;                     \
static dispatch_once_t __singleton__token__##__token;       \
+ (instancetype)sharedInstance \
{ \
dispatch_once( &__singleton__token__##__token, ^{ __singleton__objc__##__token = [[self alloc] init]; } ); \
return __singleton__objc__##__token; \
}   \
+ (void)purgeSharedInstance \
{   \
__singleton__objc__##__token = nil;    \
__singleton__token__##__token = 0; \
}


// 定义静态常量字符串
#define hw_staticConstString(__string)               static const char * __string = #__string;


#define ZYNotificationCenter [NSNotificationCenter defaultCenter]
#define ZYUserDefaults [NSUserDefaults standardUserDefaults]



//// @interface
//#define singleton_interface(className) \
//+ (className *)shared##className;
//
//
//// @implementation
//#define singleton_implementation(className) \
//static className *_instance; \
//+ (id)allocWithZone:(NSZone *)zone \
//{ \
//static dispatch_once_t onceToken; \
//dispatch_once(&onceToken, ^{ \
//_instance = [super allocWithZone:zone]; \
//}); \
//return _instance; \
//} \
//+ (className *)shared##className \
//{ \
//static dispatch_once_t onceToken; \
//dispatch_once(&onceToken, ^{ \
//_instance = [[self alloc] init]; \
//}); \
//return _instance; \
//}
//

#endif /* SCPredefine_h */
